<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录 - 老年健康服务平台</title>
    <link rel="stylesheet" href="styles.css">
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f9;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }

        .login-container {
            background: #fff;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            width: 100%;
            max-width: 400px;
        }

        .login-container h2 {
            text-align: center;
            color: #0066cc;
            margin-bottom: 20px;
        }

        .form-group {
            margin-bottom: 15px;
        }

        .form-group label {
            display: block;
            font-weight: bold;
            margin-bottom: 5px;
        }

        .form-group input {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
            box-sizing: border-box;
        }

        .form-group input:focus {
            outline: none;
            border-color: #0066cc;
        }

        .btn {
            background-color: #0066cc;
            color: white;
            padding: 10px 15px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            width: 100%;
            font-size: 1rem;
        }

        .btn:hover {
            background-color: #004080;
        }

        .error-message {
            color: red;
            font-size: 0.9rem;
            margin-top: 10px;
            text-align: center;
        }

        .success-message {
            color: green;
            font-size: 0.9rem;
            margin-top: 10px;
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="login-container">
        <h2>老年健康服务平台登录</h2>
        <form id="loginForm">
            <div class="form-group">
                <label for="username">用户名</label>
                <input type="text" id="username" name="username" placeholder="请输入用户名" required>
            </div>
            <div class="form-group">
                <label for="password">密码</label>
                <input type="password" id="password" name="password" placeholder="请输入密码" required>
            </div>
            <button type="submit" class="btn">登录</button>
            <div id="message" class="error-message"></div>
        </form>
    </div>

    <script>
        // 定义预设用户名和密码
        const validUsername = "user";
        const validPassword = "123456";

        // 获取表单和消息元素
        const loginForm = document.getElementById("loginForm");
        const messageDiv = document.getElementById("message");

        // 处理登录表单提交
        loginForm.addEventListener("submit", function(event) {
            event.preventDefault(); // 阻止默认表单提交行为

            const username = document.getElementById("username").value;
            const password = document.getElementById("password").value;

            // 简单前端认证
            if (username === validUsername && password === validPassword) {
                messageDiv.textContent = "登录成功！正在跳转...";
                messageDiv.className = "success-message";
                // 模拟跳转到首页
                setTimeout(() => {
                    window.location.href = "{{ url_for('index') }}";
                }, 1500);
            } else {
                messageDiv.textContent = "用户名或密码错误，请重试！";
                messageDiv.className = "error-message";
            }
        });
    </script>
</body>
</html>
